﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bzzb.Model;
using DnsClient.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;

namespace Bzzb.Controllers
{
    public class MenuController : BaseController
    {
        private readonly ILogger<MenuController> _logger;
        public MenuController(ILogger<MenuController> logger, IFreeSql fsql) : base(fsql)
        {
            this._logger = logger;
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Index()
        {
            string permission_json = @"[{""id"":1,""name"":""可视化运维"",""pid"":0,""icon"":""yibiaopan"",""path"":""operation"",""components"":""Operation"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":2,""name"":""保障装备库"",""pid"":0,""icon"":""jichushezhi"",""path"":""ensureEquip"",""components"":""EnsureEquip"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":3,""name"":""保障车辆"",""pid"":2,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""car"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":4,""name"":""新建车辆"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":5,""name"":""删除车辆"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":6,""name"":""编辑车辆"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":7,""name"":""查看车辆"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""viewCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":8,""name"":""配置字段"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""configCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":9,""name"":""下载模板"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":10,""name"":""导入"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":11,""name"":""导出"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":12,""name"":""新建定期控制项"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":13,""name"":""删除定期控制项"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":14,""name"":""编辑定期控制项"",""pid"":3,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":15,""name"":""保障设备"",""pid"":2,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""equipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":16,""name"":""新建设备"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":17,""name"":""删除设备"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":18,""name"":""编辑设备"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":19,""name"":""查看设备"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""viewEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":20,""name"":""配置字段"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""configEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":21,""name"":""下载模板"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":22,""name"":""导入"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":23,""name"":""导出"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":24,""name"":""新建定期控制项"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":25,""name"":""删除定期控制项"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":26,""name"":""编辑定期控制项"",""pid"":15,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":27,""name"":""保障工具"",""pid"":2,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""toolkit"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":28,""name"":""新建工具箱"",""pid"":27,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createToolkit"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":29,""name"":""删除工具箱"",""pid"":27,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeToolkit"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":30,""name"":""编辑工具箱"",""pid"":27,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorToolkit"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]}]},{""id"":31,""name"":""保障装备构件"",""pid"":0,""icon"":""renwu"",""path"":""ensureEquipBuild"",""components"":""EnsureEquipBuild"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":32,""name"":""保障车辆"",""pid"":31,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""car"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":33,""name"":""新建车辆构件"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":34,""name"":""删除车辆构件"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":35,""name"":""编辑车辆构件"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":36,""name"":""配置字段"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""configCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":37,""name"":""下载模板"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":38,""name"":""导入"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":39,""name"":""导出"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":40,""name"":""新建定期控制项"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":41,""name"":""删除定期控制项"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":42,""name"":""编辑定期控制项"",""pid"":32,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorControlCar"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":43,""name"":""保障设备"",""pid"":31,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""equipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":44,""name"":""新建设备构件"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":45,""name"":""删除设备构件"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":46,""name"":""编辑设备构件"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":47,""name"":""配置字段"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""configEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":48,""name"":""下载模板"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":49,""name"":""导入"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":50,""name"":""导出"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":51,""name"":""新建定期控制项"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":52,""name"":""删除定期控制项"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":53,""name"":""编辑定期控制项"",""pid"":43,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorControlEquipment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]}]},{""id"":54,""name"":""维修保障信息库"",""pid"":0,""icon"":""renwuxiangqing"",""path"":""maintains"",""components"":""Maintains"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":55,""name"":""故障排除信息"",""pid"":54,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""fault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":56,""name"":""新建故障信息"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":57,""name"":""删除故障信息"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":58,""name"":""编辑故障信息"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":59,""name"":""配置字段"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""configFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":60,""name"":""下载模板"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":61,""name"":""导入"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":62,""name"":""导出"",""pid"":55,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportFault"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":63,""name"":""日常使用信息"",""pid"":54,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""daily"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":64,""name"":""定期维护记录"",""pid"":54,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""record"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":65,""name"":""定期维护状态"",""pid"":0,""icon"":""gerengongzuotai"",""path"":""termlyMaintain"",""components"":""TermlyMaintain"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":66,""name"":""完成维护"",""pid"":65,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""completeMaintenance"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":67,""name"":""查看"",""pid"":65,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":68,""name"":""基础数据管理"",""pid"":0,""icon"":""xitong"",""path"":""dataAdmin"",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":69,""name"":""工具库"",""pid"":68,""icon"":"""",""path"":""toolMagazine"",""components"":""BasicDataManage/toolMagazine"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":70,""name"":""新建工具"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":71,""name"":""删除工具"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":72,""name"":""编辑工具"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":73,""name"":""下载模板"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""templateTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":74,""name"":""导入"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""importTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":75,""name"":""导出"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""exportTool"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":76,""name"":""查看"",""pid"":69,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":77,""name"":""机型"",""pid"":68,""icon"":"""",""path"":""machineType"",""components"":""BasicDataManage/machineType"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":78,""name"":""新建机型"",""pid"":77,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createModels"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":79,""name"":""删除机型"",""pid"":77,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeModels"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":80,""name"":""编辑机型"",""pid"":77,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorModels"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":81,""name"":""查看"",""pid"":77,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":82,""name"":""计时项"",""pid"":68,""icon"":"""",""path"":""timers"",""components"":""BasicDataManage/timers"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":83,""name"":""新建计时项"",""pid"":82,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createTiming"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":84,""name"":""删除计时项"",""pid"":82,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeTiming"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":85,""name"":""编辑计时项"",""pid"":82,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorTiming"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":86,""name"":""查看"",""pid"":82,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":87,""name"":""位置信息管理"",""pid"":68,""icon"":"""",""path"":""location"",""components"":""BasicDataManage/location"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":88,""name"":""新建位置信息"",""pid"":87,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createLocation"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":89,""name"":""删除位置信息"",""pid"":87,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeLocation"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":90,""name"":""编辑位置信息"",""pid"":87,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorLocation"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":91,""name"":""查看"",""pid"":87,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]}]},{""id"":92,""name"":""组织管理"",""pid"":0,""icon"":""zuzhi"",""path"":""organization"",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":93,""name"":""用户管理"",""pid"":92,""icon"":"""",""path"":""user"",""components"":""OrganizationManage/department"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":94,""name"":""新建部门"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createDepartment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":95,""name"":""删除部门"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeDepartment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":96,""name"":""编辑部门"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorDepartment"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":97,""name"":""新建用户"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createUser"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":98,""name"":""删除用户"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeUser"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":99,""name"":""编辑用户"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorUser"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":100,""name"":""查看"",""pid"":93,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":101,""name"":""权限管理"",""pid"":92,""icon"":"""",""path"":""role"",""components"":""OrganizationManage/role"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[{""id"":102,""name"":""新建角色"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""createRole"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":103,""name"":""删除角色"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""removeRole"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":104,""name"":""编辑角色"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""editorRole"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":105,""name"":""权限维护"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""permissionMaintain"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":106,""name"":""成员维护"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":""membersMaintenance"",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]},{""id"":107,""name"":""查看"",""pid"":101,""icon"":"""",""path"":"""",""components"":"""",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]},{""id"":108,""name"":""日志管理"",""pid"":92,""icon"":"""",""path"":""log"",""components"":""OrganizationManage/logManager"",""btnPermissions"":"""",""created"":""2020-12-09 15:30:00"",""updated"":""2020-12-09 15:30:00"",""children"":[]}]}]";
            return RenderJson(data: JArray.Parse(permission_json));
            //JArray data = getMenuTreeData(0).Result;
            //return RenderJson(data: data);
        }

        [NonAction]
        public async Task<JArray> getMenuTreeData(long pid) {
            JArray data = new JArray();
            List<Menu> menus = await _fsql.Select<Menu>().Where(m => m.Pid == pid).ToListAsync();
            if (menus != null && menus.Count > 0) {
                foreach (var menu in menus)
                {
                    JObject jo_menu = JObject.FromObject(menu);
                    jo_menu.Add("children", getMenuTreeData(menu.Id).Result);
                    data.Add(jo_menu);
                }
            }
            return data;
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Save([FromForm] User user)
        {
            string status = "failed";
            string message = "该用户已存在";
            int code = -1;
            // 判断用户是否存在
            User isExistsUser = await _fsql.Select<User>().Where(u => u.Username == user.Username).ToOneAsync();
            if (isExistsUser == null)
            {
                long id = await _fsql.Insert(user).ExecuteIdentityAsync();
                user.Id = id;
                status = "success";
                message = "添加用户成功";
                code = 0;
            }
            return RenderJson(status: status, message: message, code: code, data: user);
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Delete([FromForm] long id) {
            User user = await _fsql.Select<User>().Where(u => u.Id == id).ToOneAsync();
            if (user.Username.Equals("admin")) {
                return RenderJson(status: "failed", message: "管理员无法删除", code: -1, data: user);
            }
            int affrows = await _fsql.Delete<User>().Where(u => u.Id == id).ExecuteAffrowsAsync();
            return RenderJson(data: affrows);
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Update([FromForm] User user) {
            int affrows = await _fsql.Update<User>().SetSourceIgnore(user, colval => colval == null).ExecuteAffrowsAsync();
            return RenderJson(data: affrows);
        }

        [HttpGet]
        public async Task<IDictionary<string, Object>> Show([FromQuery] long id) {
            User user = await _fsql.Select<User>().Where(u => u.Id == id).ToOneAsync();
            return RenderJson(data: user);
        }
    }
}
